package com.jh.complicate.socket.single;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title ClientSocketDemo.java
 * @package com.jh.complicate.socket.single
 * @description 客户端Socket例子
 * @date 2019-05-31 17:21
 */
public class ClientSocketDemo {

    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter out = null;

        try {
            socket = new Socket("127.0.0.1", 8080);
            out = new PrintWriter(socket.getOutputStream(), true);
            out.print("Hello World");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != out) {
                out.close();
            }

            if (null != socket) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
